/**
 * Created by Mikey on 2017/4/21.
 */
$(document).ready(function() {
    fileUpload();
});
$.ajax({
    type: "GET",
    url: "/getData.json",
    data: {},
    dataType: "json",
    success: function(data){
        chart(data.x,data.y);
    }
});

function chart(x,y) {
    var chart = new Highcharts.Chart('container', {
        title: {
            text: '不同城市的月平均气温',
        },
        subtitle: {
            text: '数据来源: WorldClimate.com',
        },
        xAxis: {
            categories: x
        },
        yAxis: {
            title: {
                text: '温度 (°C)'
            }
        },

        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [{
            name: '东京',
            data: y
        }]
    });
}

function fileUpload() {
    $("#upload").uploadify({
        "auto" : false,                                         //是否自动上传
        "buttonClass" : "uploadBtn",                            //给上传按钮定义class名称
        "uploader": "/uploadFile.json",
        "method": "post",
        "progressData": "percentage",
        "swf": "../uploadify/uploadify.swf",
        "buttonText": "选择要上传的文件",
        "multi": true,
        "fileSizeLimit": '1000MB',
        "queueSizeLimit": 5,
        "successTimeout": 600,
        "onUploadSuccess": function(file, data, response) {
            alert('The file ' + file.name
                + ' was successfully uploaded with a response of '
                + response + ':' + data);
        },
        "onUploadError": function(file, errorCode, errorMsg,
                                  errorString) {
            alert('The file ' + file.name
                + ' could not be uploaded: ' + errorString);
        },
        "onSelectError": function() {
            alert('The file ' + file.name
                + ' returned an error and was not added to the queue.');
        }
    });

}
